package edu.hwadee.serviceImpl;

import java.util.List;

import edu.hwadee.entity.Officematerialuse;
import edu.hwadee.service.OfficematerialuseService;

public class OfficematerialuseServiceImpl extends BasicServiceImpl implements OfficematerialuseService {

	@Override
	public boolean save(Officematerialuse officematerialuse) {
		try {
			getOfficematerialuseDAO().save(officematerialuse);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean delete(Officematerialuse officematerialuse) {
		try {
			getOfficematerialuseDAO().delete(officematerialuse);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Officematerialuse> search(Officematerialuse officematerialuse) {
		try {
			return (List<Officematerialuse>)getOfficematerialuseDAO().findByExample(officematerialuse);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Officematerialuse searchById(Integer officematerialuseId) {
		try {
			return getOfficematerialuseDAO().findById(officematerialuseId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean update(Officematerialuse officematerialuse) {
		try {
			if(searchById(officematerialuse.getOfficematerialUseId()) != null) {
				getOfficematerialuseDAO().merge(officematerialuse);
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Officematerialuse> showAll() {
		try {
			return (List<Officematerialuse>)getOfficematerialuseDAO().findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
